#include <algorithm>
#include <cstring>
#include <iostream>

using namespace std;

int n, m, k;
int dp[(1 << 20) + 10];
int v[110];

int main() {
    memset(dp, 0x3f, sizeof(dp));
    cin >> n >> m >> k;
    for (int i = 0; i < n; i++) {
        int p = 0;
        for (int j = 0; j < k; j++) {
            int c;
            cin >> c;
            c--;
            p |= (1 << c);
        }
        dp[p] = 1;
        v[i] = p;
    }

    for (int s = 1; s < (1 << m); s++) {
        for (int i = 0; i < n; i++) {
            dp[s | v[i]] = min(dp[s | v[i]], dp[s] + 1);
        }
    }

    if (dp[(1 << m) - 1] > n)
        cout << -1;
    else
        cout << dp[(1 << m) - 1];
}